home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / ubmalm.zip / prroot.ub < prev    next >
Text File  |  1990-08-22  |  659b  |  17 lines

  1.  1050   fnPrroot(N)
  2.  1060   ' Returns the smallest positive primitive root of n, which
  3.  1070   ' is assumed prime.  N-1 must be factorable by the function prmdiv.
  4.  1080   ' Returns 0 for failure or error.
  5.  1090   local R=1,Factor,N1,Te,T,Tt,F%
  6.  1100   if N<3 then if N=2 then return(1) else return(0) endif endif
  7.  1110   N1=N-1
  8.  1120   repeat inc R:Te=N1:F%=1
  9.  1130   repeat
  10.  1140   Factor=prmdiv(Te):if Factor=0 then return(0) endif
  11.  1150   repeat Te=Te\Factor until res
  12.  1160   Te=Factor*Te+res:Tt=N1\Factor
  13.  1170   T=modpow(R,Tt,N)
  14.  1180   if T=1 then F%=0:Te=1 endif
  15.  1190   until Te=1:until F%
  16.  1200   return(R) ' End of function Prroot.
  17.